package org.eclipse.emf.cdo.ui.merge;

import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDAndVersion;
import org.eclipse.emf.cdo.common.model.CDOModelConstants;
import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
import org.eclipse.emf.cdo.internal.common.id.CDOIDAndVersionImpl;
import org.eclipse.emf.cdo.spi.common.revision.BaseCDORevision;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * The tree node object for the tree containing the change operations.
 *
 * @author Thomas Halmetschlager
 */
public class MergeTreeParent extends TreeParent{

	/** The revision key. */
	private CDORevisionKey revision;
	
	/** The CDO ID. */
	private CDOIDAndVersion cdoid;
	
	/** The branchpoint. */
	private CDOBranchPoint branch;
	
	/**
	 * Instantiates a new merge tree parent.
	 *
	 * @param name the name
	 */
	public MergeTreeParent(String name){
		super(name);
	}
	
	/**
	 * Returns the branch point.
	 *
	 * @return the branch point
	 */
	public CDOBranchPoint getBranch() {
		return branch;
	}

	/**
	 * Sets the branch point.
	 *
	 * @param branch the new branch point 
	 */
	public void setBranch(CDOBranchPoint branch) {
		this.branch = branch;
	}

	/**
	 * Instantiates a new merge tree parent with the revision as name.
	 *
	 * @param revision the revision
	 */
	public MergeTreeParent( CDORevisionKey revision) {
		super(revision.toString());
		this.revision = revision;
		this.cdoid = new CDOIDAndVersionImpl(revision.getID(), revision.getVersion()) ;
		
	}
	
	/**
	 * Instantiates a new merge tree parent.
	 *
	 * @param revision the revision
	 * @param name the name
	 */
	public MergeTreeParent( CDORevisionKey revision, String name) {
		super(name);
		this.revision = revision;
		this.cdoid  = new CDOIDAndVersionImpl(revision.getID(), revision.getVersion()) ;
		
	}

	/**
	 * Instantiates a new merge tree parent, only for nodes that will be deleted.
	 * The name of the node is "Delete <CdoId>"
	 *
	 * @param id the id
	 */
	public MergeTreeParent( CDOIDAndVersion id) {
		super("Delete: " + id.toString());
		this.revision = null;
		this.cdoid = id;
	}
	
	/**
	 * Returns the revision key.
	 *
	 * @return the revision key
	 */
	public CDORevisionKey getRevision() {
		return revision;
	}

	/**
	 * Sets the revision key .
	 *
	 * @param revision the new revision key
	 */
	public void setRevision(CDORevisionKey revision) {
		this.revision = revision;
	}

	/**
	 * Gets the CDO ID.
	 *
	 * @return the CDO ID
	 */
	public CDOIDAndVersion getCdoid() {
		return cdoid;
	}

	/**
	 * Sets the CDO ID.
	 *
	 * @param cdoid the new CDO ID
	 */
	public void setCdoid(CDOIDAndVersion cdoid) {
		this.cdoid = cdoid;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.emf.cdo.ui.merge.TreeObject#toString()
	 */
	@Override
	public String toString(){
		return getName();
	}
}
